import axios from '@/utils/request';


/**
 * 根据商品所有分类树
 */
 export async function QueryProductCategroyTree() {
    const res = await axios.get('/ProductCategories/QueryTreeCategoriesView');
    if (res.data.code === 200) {
        return res.data.data;
    }
    return Promise.reject(new Error(res.data.msg));
}
/**
 * 根据条件查询产品分类
 */
 export async function QueryProductCategroy(params) {
    const res = await axios.post('/ProductCategories/QueryProductCategoryByCondition',params);
    if (res.data.code === 200) {
        return res.data.data;
    }
    return Promise.reject(new Error(res.data.msg));
}
/**
 * 根据条件添加分类
 */
 export async function AddProductCategroy(params) {
    const res = await axios.post('/ProductCategories/AddCategories',params);
    if (res.data.code === 200) {
        return res.data.msg;
    }
    return Promise.reject(new Error(res.data.msg));
}

/**
 * 根据条件修改分类
 */
 export async function UpdateProductCategroy(params) {
    const res = await axios.post('/ProductCategories/UpdateCategories',params);
    if (res.data.code === 200) {
        return res.data.msg;
    }
    return Promise.reject(new Error(res.data.msg));
}

/**
 * 是否推荐首页操作
 */
 export async function SetCategroyIsDefault(id,isdefault) {
    const res = await axios.post('/ProductCategories/SetCategoriesIsDefault?id='+id+'&isDefault='+isdefault);
    if (res.data.code === 200) {
        return res.data.msg;
    }
    return Promise.reject(new Error(res.data.msg));
}


/**
 * 根据条件删除分类
 */
 export async function Deleted(id) {
    const res = await axios.post('/ProductCategories/DeleteCategories?id='+id);
    if (res.data.code === 200) {
        return res.data.msg;
    }
    return Promise.reject(new Error(res.data.msg));
}


/**
 * 根据Id查询商品分类
 */
 export async function QueryProductCategroyById(id) {
    const res = await axios.get('/ProductCategories/QueryProductCategroyById?id='+id);
    if (res.data.code === 200) {
        return res.data.data;
    }
    return Promise.reject(new Error(res.data.msg));
}